package net.dwade.loader.service.impl;

import net.dwade.loader.service.AppRecommendService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 该实现类仅用于模拟热插拔
 */
public class AppRecommenServiceV1 implements AppRecommendService, ApplicationContextAware, InitializingBean {

    private static final Logger logger = LoggerFactory.getLogger(AppRecommenServiceV1.class);

    /**
     * 测试自动注入功能
     */
    @Resource
    private ApplicationContext applicationContext;

    @Override
    public Map<Integer, Double> recommend(String imei, List<Integer> appIds) {
        logger.info("recommend by v1!");
        return null;
    }

    /**
     * 测试是否支持 spring 的相关bean周期
     * @param applicationContext
     * @throws BeansException
     */
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        logger.info("The method named 'setApplicationContext' was invoked.");
    }

    /**
     * 测试是否支持 spring 的相关bean周期
     * @throws Exception
     */
    @Override
    public void afterPropertiesSet() throws Exception {
        logger.info("ApplicationContext:{}", this.applicationContext);
        logger.info("The method named 'afterPropertiesSet' was invoked.");
    }
}
